﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using com.kmer;
using com.kmer.interfaces;

namespace com.kmer.library.Factorys {
    /// <summary>
    /// 消息中心
    /// </summary>
    public class MessageCenterFactory {
        private static IMessageCenter _cache;
        private static Type _factoryType;

        /// <summary>
        /// 实例
        /// </summary>
        public static IMessageCenter Instance => _cache ?? (_cache = BaseFactory<IMessageCenter, TestMessageCenterFactory>.GetService(FactoryType));

        /// <summary>
        /// 实现此工程的实例类型
        /// </summary>
        public static Type FactoryType {
            get { return _factoryType; }
            set {
                if (_factoryType != value)
                    _cache = null;
                _factoryType = value;

            }
        }
    }

	/// <summary>
	/// 消息中心
	/// </summary>
	public class TestMessageCenterFactory : IMessageCenter {
		/// <summary>
		/// 发送消息
		/// </summary>
		/// <param name="msgType"></param>
		/// <param name="CusId"></param>
		/// <param name="Title"></param>
		/// <param name="Data"></param>
		/// <param name="appId">appId</param>
		/// <returns></returns>
		public int Send(int msgType, int CusId, string Title, object Data, string appId)
	    {
			Log.WriteLines("TestMessageCenterFactory.Send", "什么都没做");
			return 0;
		}

		public int Send(int msgType, int CusId, string Title, object Data, Guid appId)
		{
			Log.WriteLines("TestMessageCenterFactory.Send", "什么都没做");
			return 0;
		}

		/// <summary>
		/// 异步发送消息
		/// </summary>
		/// <param name="msgType"></param>
		/// <param name="CusId"></param>
		/// <param name="Title"></param>
		/// <param name="Data"></param>
		/// <param name="appId">appId</param>
		/// <returns></returns>
		public Task<int> SendSync(int msgType, int CusId, string Title, object Data, string appId)
	    {
			Log.WriteLines("TestMessageCenterFactory.SendSync", "什么都没做");
			return Task.FromResult(0);
		}

		public Task<int> SendSync(int msgType, int CusId, string Title, object Data, Guid appId)
		{
			Log.WriteLines("TestMessageCenterFactory.SendSync", "什么都没做");
			return Task.FromResult(0);
		}

		/// <summary>
		/// 发送信息给多个用户（相同的信息）
		/// </summary>
		/// <param name="msgType"></param>
		/// <param name="Users"></param>
		/// <param name="Title"></param>
		/// <param name="Data"></param>
		/// <param name="appId">appId</param>
		/// <returns></returns>
		public void SendToUsers(int msgType, IEnumerable<int> Users, string Title, object Data, string appId)
	    {
			Log.WriteLines("TestMessageCenterFactory.SendToUsers", "什么都没做");
		}

		public void SendToUsers(int msgType, IEnumerable<int> Users, string Title, object Data, Guid appId)
		{
			Log.WriteLines("TestMessageCenterFactory.SendToUsers", "什么都没做");
		}

		/// <summary>
		/// 异步发送信息给多个用户（相同的信息）
		/// </summary>
		/// <param name="msgType"></param>
		/// <param name="Users"></param>
		/// <param name="Title"></param>
		/// <param name="Data"></param>
		/// <param name="appId">appId</param>
		public Task SendToUsersSync(int msgType, IEnumerable<int> Users, string Title, object Data, string appId)
	    {
			Log.WriteLines("TestMessageCenterFactory.SendToUsers", "什么都没做");
		    return Task.Run(() => { });
	    }

		public Task SendToUsersSync(int msgType, IEnumerable<int> Users, string Title, object Data, Guid appId)
		{
			Log.WriteLines("TestMessageCenterFactory.SendToUsers", "什么都没做");
			return Task.Run(() => { });
		}
	}
}
namespace com.kmer.library {
    /// <summary>
    /// 消息中心
    /// </summary>
    public interface IMessageCenter:IFactory {
	    /// <summary>
	    /// 发送消息
	    /// </summary>
	    /// <param name="msgType"></param>
	    /// <param name="CusId"></param>
	    /// <param name="Title"></param>
	    /// <param name="Data"></param>
	    /// <param name="appId">appId</param>
	    /// <returns></returns>
	    int Send(int msgType, int CusId, string Title,object Data, string appId);
		int Send(int msgType, int CusId, string Title, object Data, Guid appId);

		/// <summary>
		/// 异步发送消息
		/// </summary>
		/// <param name="msgType"></param>
		/// <param name="CusId"></param>
		/// <param name="Title"></param>
		/// <param name="Data"></param>
		/// <param name="appId">appId</param>
		/// <returns></returns>
		Task<int> SendSync(int msgType, int CusId, string Title, object Data, string appId);
		Task<int> SendSync(int msgType, int CusId, string Title, object Data, Guid appId);

		/// <summary>
		/// 发送信息给多个用户（相同的信息）
		/// </summary>
		/// <param name="msgType"></param>
		/// <param name="Users"></param>
		/// <param name="Title"></param>
		/// <param name="Data"></param>
		/// <param name="appId">appId</param>
		/// <returns></returns>
		void SendToUsers(int msgType, IEnumerable<int> Users, string Title, object Data, string appId);
		void SendToUsers(int msgType, IEnumerable<int> Users, string Title, object Data, Guid appId);

		/// <summary>
		/// 异步发送信息给多个用户（相同的信息）
		/// </summary>
		/// <param name="msgType"></param>
		/// <param name="Users"></param>
		/// <param name="Title"></param>
		/// <param name="Data"></param>
		/// <param name="appId">appId</param>
		Task SendToUsersSync(int msgType, IEnumerable<int> Users, string Title, object Data, string appId);
		Task SendToUsersSync(int msgType, IEnumerable<int> Users, string Title, object Data, Guid appId);
	}
}